package com.turnengine.client.local.upkeep.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Upkeep.
 */
public class Upkeep implements IUpkeep, Comparable<IUpkeep> {

	/** The upkeep id. */
	private int upkeepId = -1;
	/** The priority. */
	private int priority = 0;

	/**
	 * Creates a new Upkeep.
	 */
	public Upkeep() {
	}

	/**
	 * Creates a new Upkeep.
	 * @param upkeepId the upkeep id
	 * @param priority the priority
	 */
	public Upkeep(int upkeepId, int priority) {
		setUpkeepId(upkeepId);
		setPriority(priority);
	}

	/**
	 * Creates a new Upkeep.
	 * @param upkeep the upkeep
	 */
	public Upkeep(Upkeep upkeep) {
		setUpkeepId(upkeep.getUpkeepId());
		setPriority(upkeep.getPriority());
	}

	/**
	 * Creates a new Upkeep.
	 * @param iUpkeep the i upkeep
	 */
	public Upkeep(IUpkeep iUpkeep) {
		setUpkeepId(iUpkeep.getUpkeepId());
		setPriority(iUpkeep.getPriority());
	}

	/**
	 * Returns the upkeep id.
	 * @return the upkeep id.
	 */
	public int getUpkeepId() {
		return upkeepId;
	}

	/**
	 * Returns the priority.
	 * @return the priority.
	 */
	public int getPriority() {
		return priority;
	}

	/**
	 * Sets the upkeep id.
	 * @param upkeepId the upkeep id to set.
	 */
	public void setUpkeepId(int upkeepId) {
		this.upkeepId = upkeepId;
	}

	/**
	 * Sets the priority.
	 * @param priority the priority to set.
	 */
	public void setPriority(int priority) {
		this.priority = priority;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(1277, 37);
		hash.append(upkeepId);
		hash.append(priority);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof Upkeep) {
			Upkeep compare = (Upkeep) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.upkeepId, compare.upkeepId);
			equals.append(this.priority, compare.priority);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IUpkeep compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.upkeepId, compare.getUpkeepId());
		builder.append(this.priority, compare.getPriority());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("upkeepId", upkeepId);
		string.append("priority", priority);
		return string.toString();
	}
}
